package com.ruoyi.common.pub.vo;

import lombok.Data;

@Data
public class Response<T>{
    private String code;

    private T data;

    private String msg;

    private Page page;

    private Response(){}

    private Response(String code, T data, String msg, Page page) {
        this.code = code;
        this.data = data;
        this.msg = msg;
        this.page = page;
    }

    public static <T> Response success(T data){
        return success(data,null);
    }

    public static <T> Response success(T data,Page page){
        return new Response<>(WebStatus.SUCCESS.getCode(),data,null,page);
    }

    public static <T> Response failed(WebStatus status){
        return new Response(status.getCode(),null,status.getMsg(),null);
    }

    public static <T> Response failed(){
        return new Response(WebStatus.FAILED.getCode(),null,WebStatus.FAILED.getMsg(),null);
    }

    public Response<T> code(String code){
        this.code = code;
        return this;
    }
    public Response<T> msg(String msg){
        this.msg = msg;
        return this;
    }
    public Response<T> data(T data){
        this.data = data;
        return this;
    }
    public Response<T> page(Page page){
        this.page = page;
        return this;
    }
}
